import 'package:flutter/material.dart';
import './MenuItem.dart';
import '../circular/index.dart';

class Menu extends Wrap{

  Menu({
    super.key,
    required BuildContext context,
    double? height,
    required List<MenuItem> items
  }) :
    super (
        spacing: 0, // 列间距
        runSpacing: 0,
        children: getChildren(items, context, height)
    );

  static List<Widget> getChildren(List<MenuItem> items, BuildContext context, double? height){
    return items.map((child) => GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: child.onTap,
      child: Container(
        width: (MediaQuery.of(context).size.width/3),
        height: height ?? 120,
        decoration: const BoxDecoration(
          border: Border(
            right: BorderSide(
                width: 1,
                color: Color.fromARGB(255, 238, 238, 238)
            ),
            bottom: BorderSide(
                width: 1,
                color: Color.fromARGB(255, 238, 238, 238)
            ),
          ),
        ),
        child: Center(
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.only(top: 10),
                child: Circular(
                    width: (MediaQuery.of(context).size.width/6),
                    height: (MediaQuery.of(context).size.width/6),
                    backgroundColor: child.color ?? const Color.fromARGB(255, 237, 142, 98),
                    child: child.icon ?? const Icon(Icons.add, color: Colors.white,size: 40)
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 5),
                child: Text(child.text, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600),),
              )
            ],
          ),
        ),
      )
    )).toList();
  }
}

